#ifndef __LIFT_INFO_H__
#define __LIFT_INFO_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdbool.h>

#define LIFT_MIN_SPEED  10
#define LIFT_STATE_CNT  10

#define LIFT_CAN_MAX_DISCONNECT_MS  500
#define LIFT_SENSOR_MAX_ERR_CNT     20

#define DEFUALT_MAX_HEIGHT_THAN_TOP     150
#define DEFUALT_SUL_HEIGHT_THAN_TOP     50

#define LIFT_SLOW_DOWN_ZONE  80

struct floor_info {
    uint32_t flat_pos;
    uint32_t up_slow_down_pos;
    uint32_t down_slow_down_pos;
    uint32_t up_flat_pos;
    uint32_t down_flat_pos;
    uint32_t up_flat_trimming_pos;
    uint32_t down_flat_trimming_pos;
};

struct lift_oc_flag {
    uint8_t overspeed : 1;
    uint8_t can_comm_err : 1;
    uint8_t sensor_disconn : 1;
    uint8_t overheight : 1;
};

union lift_oc {
    uint8_t value;
    struct lift_oc_flag oc_flag;
};

struct lift_ctrl_handle {
    uint16_t specified_speed;
    struct floor_info floor_info[5];
    uint32_t up_slow_down_pos;
    uint32_t down_slow_down_pos;
    uint32_t up_flat_pos;
    uint32_t down_flat_pos;
    uint32_t max_height_pos;
    uint32_t sul_pos;
    uint16_t password;
    uint16_t hardware_test;
    union lift_oc oc_flag;
    uint8_t total_floor;
    bool is_cover_enable;
    bool is_floor_info_learned;
    int8_t current_floor;
};

extern struct lift_ctrl_handle lift;

void lift_ctrl_reset_total_floor(uint8_t floor);
void lift_ctrl_set_flat_pos(uint8_t floor, uint32_t pos);
void lift_ctrl_set_up_flat_trimming_pos(uint8_t floor, uint16_t trimming_pos);
void lift_ctrl_set_down_flat_trimming_pos(uint8_t floor, uint16_t trimming_pos);

bool lift_is_floor_info_learned(void);
void lift_disconnect_check(void);
void lift_info_analysis(uint8_t *data);
int lift_info_get_position(uint32_t *position);

#ifdef __cplusplus
}
#endif

#endif

